from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
class UserInfoPage():
    def __init__(self,driver):
        self.driver = driver
    user_head_loc = (By.XPATH, '//*[@id="preview"]')
    select_loc = (By.XPATH,'//*[@id="filePicker2"]/div[2]/input')
    iframe_loc = (By.CSS_SELECTOR,'[id *="layui-layer-iframe"]')
    saveimg_loc = (By.CSS_SELECTOR,'[class="saveBtn"]')


    def upload_user_head_img(self,path):
        self.driver.find_element(*self.user_head_loc).click()
        self.switch_into_frame()
        self.driver.find_element(*self.select_loc).send_keys(path)
        self.driver.find_element(*self.saveimg_loc).click()
        self.driver.switch_to.default_content()
    def switch_into_frame(self):
        sleep(2)
        self.driver.switch_to.frame(self.driver.find_element(*self.iframe_loc))
        sleep(2)

    def get_ele_attribute(self,attribute):
        value = self.driver.find_element(*self.user_head_loc).get_attribute(attribute)
        return value

    def tearDown(self):
        self.driver.refresh()
        sleep(3)

    @classmethod
    def tearDownClass(cls):
        sleep(3)
        cls.driver.quit()


